from app import db
from datetime import datetime, date

class HealthAssessment(db.Model):
    __tablename__ = 'health_assessments'
    
    id = db.Column(db.Integer, primary_key=True)
    user_id = db.Column(db.Integer, db.ForeignKey('users.id'), nullable=False)
    assessment_date = db.Column(db.DateTime, default=datetime.utcnow)
    
    # 综合评估
    overall_health_score = db.Column(db.Integer)  # 健康评分 (1-100)
    health_risk_level = db.Column(db.String(20))  # 风险等级: low/medium/high
    bmi_category = db.Column(db.String(20))  # BMI分类: underweight/normal/overweight/obese
    
    # 具体风险
    cardiovascular_risk = db.Column(db.String(20))
    diabetes_risk = db.Column(db.String(20))
    metabolic_risk = db.Column(db.String(20))
    
    # 建议
    recommendations = db.Column(db.Text)
    next_checkup_date = db.Column(db.DateTime)
    
    def to_dict(self):
        return {
            'id': self.id,
            'user_id': self.user_id,
            'assessment_date': self.assessment_date.isoformat(),
            'overall_health_score': self.overall_health_score,
            'health_risk_level': self.health_risk_level,
            'bmi_category': self.bmi_category,
            'cardiovascular_risk': self.cardiovascular_risk,
            'diabetes_risk': self.diabetes_risk,
            'metabolic_risk': self.metabolic_risk,
            'recommendations': self.recommendations,
            'next_checkup_date': self.next_checkup_date.isoformat() if self.next_checkup_date else None
        }